// Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov  Date: 22/03/2011 12:21:47 p.m.
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   SelectorDeEntradasParaFacturar.java

package com.luxsoft.sw3.impap.ui.selectores;

import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.GlazedLists;
import ca.odell.glazedlists.SortedList;
import ca.odell.glazedlists.TextFilterator;
import ca.odell.glazedlists.UniqueList;
import ca.odell.glazedlists.gui.TableFormat;
import ca.odell.glazedlists.matchers.MatcherEditor;
import ca.odell.glazedlists.swing.TextComponentMatcherEditor;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.uif.builder.ToolBarBuilder;
import com.jgoodies.uifextras.panel.HeaderPanel;
import com.luxsoft.siipap.compras.model.EntradaPorCompra;
import com.luxsoft.siipap.service.ServiceLocator2;
import com.luxsoft.siipap.swing.dialog.AbstractSelector;
import com.luxsoft.siipap.swing.utils.CommandUtils;
import com.luxsoft.siipap.swing.utils.ComponentUtils;
import com.luxsoft.siipap.swing.utils.SWExtUIManager;
import java.awt.Dimension;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class SelectorDeEntradasParaFacturar extends AbstractSelector
{

    private SelectorDeEntradasParaFacturar()
    {
        super(EntradaPorCompra.class, "");
        setTitle("Entradas pendientes por facturar ");
    }

    protected TableFormat getTableFormat(){
        return GlazedLists.tableFormat(EntradaPorCompra.class, new String[] {
            "recepcion.embarcacion"
        	, "recepcion.embarcacionRef"
            , "sucursal.nombre"
            , "documento"
            , "remision"
            , "fecha"
            , "clave"
            , "descripcion"
            , "compraDet.solicitado"
            , "cantidad"
            , "costo"
            , "contenedor"
            , "pallets"
            , "toneladasNeta"
            , "toneladaBruta"
            , "toneladaEstimada"
        }, new String[] {
             "Embarque"
        	, "Emb Ref"
        	, "Sucursal"
        	, "Docto"
        	, "BL"
        	, "Fecha"
        	, "Prod"
        	, "Desc"
        	, "Solicitado"
        	, "Recibido"
        	, "costo"
        	,"Contenedor"
        	, "Pallets"
        	, "TON (Net)"
        	, "TON (Brt)"
        	, "TON (Est)"
        });
    }

    public void initGlazedLists(){
        source = (EventList)GlazedLists.threadSafeList(new BasicEventList());
        source = new UniqueList(source, GlazedLists.beanPropertyComparator(EntradaPorCompra.class, "id"));
        sortedSource = new SortedList(buildFilterList(), getComparator());
    }
    
    private JTextField blInputText;
    
    /**
	 * Template method para instalar filtros personalizados
	 * 
	 * @param editors
	 */
	protected void installEditors(final EventList editors){
		blInputText=new JTextField(10);
		TextComponentMatcherEditor editor0=new TextComponentMatcherEditor(blInputText, GlazedLists.textFilterator("remision"));
		TextComponentMatcherEditor editor1=new TextComponentMatcherEditor(textFilter,getBasicTextFilter());
		editors.add(editor0);
		editors.add(editor1);
	}

    protected JComponent buildHeader(){
        header = new HeaderPanel("Compras pendientes de entrega", "");
        return header;
    }

    protected JComponent buildToolbar(){
        JToolBar bar = new JToolBar();
        ToolBarBuilder builder = new ToolBarBuilder(bar);        
        builder.add(buildFilterPanel());
        return builder.getToolBar();
    }

    protected JComponent buildFilterPanel(){
    	FormLayout layout=new FormLayout(
				"3dlu,l:50dlu,p,3dlu,l:50,p",
				"p");
		CellConstraints cc=new CellConstraints();
		PanelBuilder builder=new PanelBuilder(layout);
		
		JLabel l1=DefaultComponentFactory.getInstance().createTitle("BL: ");
		builder.add(l1,cc.xy(2,1));
		builder.add(this.blInputText,cc.xy(3,1));
		
		JLabel l=DefaultComponentFactory.getInstance().createTitle("Filtrar: ");
		builder.add(l,cc.xy(5,1));
		builder.add(this.textFilter,cc.xy(6,1));
		
		
		return builder.getPanel();
	}
    
    protected TextFilterator getBasicTextFilter(){
        return GlazedLists.textFilterator(new String[] {
            "remision","recepcion.documento", "clave", "descripcion", "recepcion.embarcacion", "recepcion.embarcacionRef"
        });
    }

    protected void setPreferedDimension(JComponent gridComponent){
        gridComponent.setPreferredSize(new Dimension(750, 450));
    }

    protected java.util.List getData(){
        String hql = "from EntradaPorCompra e " +
        		" left join fetch e.recepcion m " +
        		//" left join fetch m.embarcacionId x " +
        		" where e.factura is null" +
        		"  and e.recepcion.embarcacionId.autorizacionAduana!=null";
        return ServiceLocator2.getHibernateTemplate().find(hql);
    }

    public void clean(){
        source.clear();
    }
    protected void onWindowOpened(){
        load();
    }
   
    
   

    public static EntradaPorCompra seleccionar()
    {
        SelectorDeEntradasParaFacturar selector = new SelectorDeEntradasParaFacturar();
        selector.setSelectionMode(0);
        selector.open();
        if(!selector.hasBeenCanceled())
            return (EntradaPorCompra)selector.getSelected();
        else
            return null;
    }

    public static java.util.List seleccionarLista()
    {
        SelectorDeEntradasParaFacturar selector = new SelectorDeEntradasParaFacturar();
        selector.setSelectionMode(2);
        selector.open();
        if(!selector.hasBeenCanceled())
        {
            java.util.List found = new ArrayList((Collection)selector.getSelectedList());
            selector.clean();
            return found;
        } else
        {
            return null;
        }
    }

    public static void main(String args[])
    {
        SWExtUIManager.setup();
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                System.out.println(SelectorDeEntradasParaFacturar.seleccionarLista());
                System.exit(0);
            }

        }
);
    }

    private HeaderPanel header;
}
